var ns;
var app = new Vue({
    el: '#app',
    data: {
        UserName:'',
        form:{
            startMonth:9,
            ProjectID:0,
            ProjectName:'',
        },
        list: [
            { Name: '任务总数', count: 0 },
            { Name: '正常完成任务', count: 0 },
            { Name: '未完成任务', count: 0 },
            { Name: '超时完成', count: 0 },
        ],
        list2: [
            { Name: '正常完成率', count: '0.00%' },
            { Name: '超时完成率', count: '0.00%' },
        ],
        list3: [
            { Name: '总数', count: 0 },
            { Name: '环境保洁', count: 0 },
            { Name: '绿化养护', count: 0 },
            { Name: '四害消杀', count: 0 },
            { Name: '垃圾清运', count: 0 },
            { Name: '其他事件', count: 0 },
        ],//list3 临时巡查记录数量
        IsShowDate:false,
        minDate: new Date(),
        maxDate: new Date(),
        currentDate:0,
        LSsunmmary:{},
    },
    methods: {
        formatter(type, val) {
            if (type === 'year') {
                return `${val}年`;
            }
            if (type === 'month') {
                return `${val}月`;
            }
            return val;
        },
        onOpenDate:function(){
            this.IsShowDate=true;
        },
        onCancel:function(){
            this.IsShowDate=false;
        },
        onConfirm(day) {
            var that = this;
            var y = day.getFullYear();
            var m = day.getMonth() + 1;
            var d = day.getDate();
            var h = day.getHours();
            var s = day.getMinutes();
            var nowdate = y + '-' + (m >= 10 ? m : '0' + m);
            that.IsShowDate = false;
            that.form.startMonth = nowdate;
            that.get_data();
        },
        get_data: function () {
            var that = this;  
            var options = {};
            options.action = "get_user_environment_clean_plan_report";
            options.Month =that.form.startMonth+'-01';
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.list[0].count=data.info.TaskTotal;//任务总数
                        that.list[1].count=data.info.FinishTaskTotal;//完成任务
                        that.list[2].count=data.info.UnFinishTaskTotal; //未完成任务
                        that.list[3].count=data.info.OverTimeFinishTaskTotal;//超时完成
                        
                        that.list2[0].count=data.info.FinishPoint;//完成率
                        that.list2[1].count=data.info.OverTimeFinishPoint;//超时完成率

                        that.LSsunmmary=data.DataList;
                        if(that.LSsunmmary){
                            that.list3[0].count=that.LSsunmmary.Total;
                            that.list3[1].count=that.LSsunmmary.HJBJ;
                            that.list3[2].count=that.LSsunmmary.LHYH;
                            that.list3[3].count=that.LSsunmmary.SHXS;
                            that.list3[4].count=that.LSsunmmary.LJQY;
                            that.list3[5].count=that.LSsunmmary.QTSJ;
                        }  
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });

        },
        do_open_task:function(){
            var that = this;
            ns.openWin('bjlh_tasklist', '环境保洁任务列表', {
                ProjectID: that.form.ProjectID,
                ProjectName:that.form.ProjectName,
                startMonth:that.form.startMonth,
            });
        },
         //跳转临时工作记录表
         do_open_task_time:function(){
            var that = this;
            var title='临时工作记录';
            var url='bjlh_tasklist_record';
            ns.openWin(url, title, {
                ProjectID: that.form.ProjectID,
                ProjectName:that.form.ProjectName,
                startMonth:that.form.startMonth,
                IsAnalysis:false,
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.form.ID = api.pageParam.id || 0;
    //获取当前登录人姓名
    var username = api.getPrefs({
        sync: true,
        key: 'username'
    });
    app.UserName=username;
    app.minDate=new Date(moment(new Date()).add(-10, 'y'));
    app.maxDate=new Date(moment(new Date()).add(10, 'y'));
    app.currentDate=new Date();
    app.onConfirm(app.currentDate);
}
